package com.welink.cmp.adapter.api.metadata.query;

import com.welink.cmp.dto.metadata.MetadataIdListQry;
import com.welink.cmp.dto.metadata.MetadataIdQry;
import com.welink.cmp.dto.metadata.host.clientobject.HostBasicCO;
import com.welink.cmp.dto.metadata.host.clientobject.HostCO;
import com.welink.cmp.dto.metadata.host.query.HostListByPageQry;
import com.welink.cmp.meatdata.command.HostCmdExe;
import com.welink.cmp.meatdata.service.HostAppQueryService;
import com.welink.common.dto.MultiResponse;
import com.welink.common.dto.PageResponse;
import com.welink.common.dto.SingleResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 主机查询服务API
 *
 * @create
 */
@RestController("/api/host/query")
public class HostQueryServiceApi {

    @Autowired
    private HostAppQueryService hostAppQueryService;

    /**
     * [ID查询]查询主机信息详情
     * @param idQry 主键ID
     * @return Host DTO
     */
    @GetMapping("/host-item/{id}")
    public SingleResponse<HostCO> queryHostById(@PathVariable MetadataIdQry idQry){
        HostCO dto = hostAppQueryService.getHostById(idQry.getId());
        return SingleResponse.of(dto);
    }

    /**
     * [列表查询]列表查询主机信息
     * @param listQuery 列表查询指令
     * @return Host DTO列表
     */
    @GetMapping("/host-list")
    public MultiResponse<HostCO> hostAppQueryService(@RequestBody MetadataIdListQry listQuery){
        List<HostCO> list = hostAppQueryService.hostListQuery(listQuery);
        return MultiResponse.of(list);
    }

    /**
     * [分页查询]分页查询主机信息
     * @param pageQry 分页查询指令
     * @return Host DTO分页结果
     */
    @GetMapping("/host-page")
    public PageResponse<HostBasicCO> pageQueryHost(@RequestBody HostListByPageQry pageQry){
        final PageResponse<HostBasicCO> hostCOPageResponse = hostAppQueryService.hostPageQuery(pageQry);
        return hostCOPageResponse;
    }
}